package org.dong.control;


import org.dong.Tool.CodePicture;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.RenderedImage;
import java.io.IOException;

@RestController
public class CodeControl {

    @GetMapping("/Code/getCode")
    public void getCode(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        Object[] image = CodePicture.createImage();
        String codeStr = (String) image[0];
//        System.out.println(codeStr);
        HttpSession session = req.getSession();
        session.setAttribute("codeStr",codeStr);

        ImageIO.write((RenderedImage) image[1],"jpg",resp.getOutputStream());
    }
}
